package com.ranjiaqi.serializable;

import java.io.*;

/**
 * @ClassName TestSerializable
 * @Description TODO
 * @Author hp
 * @Date 2021/7/2 18:47
 * @Version 1.0
 **/
public class TestSerializable {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        writeObject(new Person("冉佳奇",20));
        readObject();
    }
    public  static  void writeObject(Person person) throws IOException {
         ObjectOutputStream objectOutput = new ObjectOutputStream(new FileOutputStream("F:/java/1.txt"));
         objectOutput.writeObject(person);
         objectOutput.close();
    }
    public  static  void readObject() throws IOException, ClassNotFoundException {
        ObjectInputStream objectInput = new ObjectInputStream(new FileInputStream("F:/java/1.txt"));
        Object o = objectInput.readObject();
        System.out.println("o = " + o);
        objectInput.close();
    }
}
